package com.xjtu.controller.admin;

import com.xjtu.dto.care.AddCareRecordDto;
import com.xjtu.dto.care.UpdateCareRecordDto;
import com.xjtu.result.PageResult;
import com.xjtu.result.Result;
import com.xjtu.service.CareRecordService;
import com.xjtu.vo.careRecord.CareRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;

@RestController
@RequestMapping("/admin/care")
@Slf4j
@Api(tags = "管理员端护理记录管理接口")
public class CareController {

    @Autowired
    private CareRecordService careRecordService;

    @PostMapping
    @ApiOperation("新增一条护理记录")
    public Result save(@RequestBody @Valid AddCareRecordDto addCareRecordDto){
        careRecordService.save(addCareRecordDto);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改一条记录")
    public Result update(@RequestBody @Valid UpdateCareRecordDto updateCareRecordDto){
        careRecordService.update(updateCareRecordDto);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除一条记录")
    public Result delete(@PathVariable @Min(value = 1,message = "id错误") Integer id){
        careRecordService.delete(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询记录")
    public Result<CareRecordVo> queryById(@PathVariable @Min(value = 1,message = "id错误") Integer id){
        CareRecordVo recordVo = careRecordService.queryById(id);
        return Result.success(recordVo);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询护理信息")
    public Result<PageResult> getMedicalVisitList(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                  @RequestParam(required = false, defaultValue = "10")Integer size,
                                                  @RequestParam(required = false, defaultValue = "null") String name){
        PageResult resp = careRecordService.pageQuery(page,size,name);
        return Result.success(resp);
    }
}
